package com.yunwaikeji.gy_tool_library.view;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.AttributeSet;
import android.view.View;

import androidx.annotation.Nullable;
import androidx.appcompat.widget.AppCompatTextView;

import com.yunwaikeji.gy_tool_library.R;
import com.yunwaikeji.gy_tool_library.interface1.GYViewBgInterface;
import com.yunwaikeji.gy_tool_library.interface1.GYViewSetInterface;
import com.yunwaikeji.gy_tool_library.set.GYViewBgBuilder;
import com.yunwaikeji.gy_tool_library.set.GYViewSetSet;
import com.yunwaikeji.gy_tool_library.utils.display.GYDisplayUtils;
import com.yunwaikeji.gy_tool_library.info.GYTextViewInfo;
import com.yunwaikeji.gy_tool_library.utils.GYTextUtils;

public class GYTextView extends AppCompatTextView implements GYViewBgInterface<GYTextView, GYTextView.GYViewBgBuilder1>, GYViewSetInterface<GYTextView, GYTextView.GYViewSet>, GYTextViewInfo {
    public static GYTextView newInstance(Context context) {
        return new GYTextView(context);
    }

    public GYTextView(Context context) {
        super(context);
        initView(null);
    }

    public GYTextView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs, 0);
        initView(attrs);
    }

    public GYTextView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(attrs);
    }

    private String digits;
    private int drawableWidthPx = -1;
    private int drawableHeightPx = -1;
    private int leftDrawableWidthPx = -1;
    private int leftDrawableHeightPx = -1;
    private int topDrawableWidthPx = -1;
    private int topDrawableHeightPx = -1;
    private int rightDrawableWidthPx = -1;
    private int rightDrawableHeightPx = -1;
    private int bottomDrawableWidthPx = -1;
    private int bottomDrawableHeightPx = -1;
    private int drawHorizontalLine = HorizontalLine.HIDE;

    private Drawable leftDrawable;
    private Drawable topDrawable;
    private Drawable rightDrawable;
    private Drawable bottomDrawable;

    private int maxLength = MATCH_PARENT;
    private int minLength = MATCH_PARENT;

    @Override
    public void initView(AttributeSet attributeSet) {
        getBackgroundBuilder(attributeSet).build();
        boolean bold = false;
        if (attributeSet != null) {
            TypedArray typedArray = getContext().obtainStyledAttributes(attributeSet, R.styleable.GYTextView, 0, 0);
            drawHorizontalLine = typedArray.getInt(R.styleable.GYTextView_drawHorizontalLine, drawHorizontalLine);
            drawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYTextView_drawableWidth, drawableWidthPx);
            drawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTextView_drawableHeight, drawableHeightPx);
            leftDrawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYTextView_leftDrawableWidth, leftDrawableWidthPx);
            leftDrawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTextView_leftDrawableHeight, leftDrawableHeightPx);
            topDrawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYTextView_topDrawableWidth, topDrawableWidthPx);
            topDrawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTextView_topDrawableHeight, topDrawableHeightPx);
            rightDrawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYTextView_rightDrawableWidth, rightDrawableWidthPx);
            rightDrawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTextView_rightDrawableHeight, rightDrawableHeightPx);
            bottomDrawableWidthPx = typedArray.getDimensionPixelSize(R.styleable.GYTextView_bottomDrawableWidth, bottomDrawableWidthPx);
            bottomDrawableHeightPx = typedArray.getDimensionPixelSize(R.styleable.GYTextView_bottomDrawableHeight, bottomDrawableHeightPx);
            leftDrawable = typedArray.getDrawable(R.styleable.GYTextView_leftDrawable);
            topDrawable = typedArray.getDrawable(R.styleable.GYTextView_topDrawable);
            rightDrawable = typedArray.getDrawable(R.styleable.GYTextView_rightDrawable);
            bottomDrawable = typedArray.getDrawable(R.styleable.GYTextView_bottomDrawable);
            bold = typedArray.getBoolean(R.styleable.GYTextView_bold, bold);
            maxLength = typedArray.getInteger(R.styleable.GYTextView_android_maxLength, maxLength);
            minLength = typedArray.getInteger(R.styleable.GYTextView_minLength, minLength);
            digits = typedArray.getString(R.styleable.GYTextView_android_digits);
            typedArray.recycle();
        }
        if (drawableWidthPx >= 0) {
            leftDrawableWidthPx = drawableWidthPx;
            topDrawableWidthPx = drawableWidthPx;
            rightDrawableWidthPx = drawableWidthPx;
            bottomDrawableWidthPx = drawableWidthPx;
        }
        if (drawableHeightPx >= 0) {
            leftDrawableHeightPx = drawableHeightPx;
            topDrawableHeightPx = drawableHeightPx;
            rightDrawableHeightPx = drawableHeightPx;
            bottomDrawableHeightPx = drawableHeightPx;
        }
        getViewSet().initDrawable();
        getViewSet().initDrawLine();
        getViewSet().setBold(bold);
        getViewSet().initFilter();
        getViewSet().setMaxLength(maxLength);
    }

    @Override
    public GYViewBgBuilder1 setBackgroundBuilder(GYViewBgBuilder1 gyViewBgBuilder1) {
        viewBgBuilder1 = gyViewBgBuilder1;
        return viewBgBuilder1;
    }

    private GYViewBgBuilder1 viewBgBuilder1;

    @Override
    public GYViewBgBuilder1 getBackgroundBuilder() {
        return getBackgroundBuilder(null);
    }

    @Override
    public GYViewBgBuilder1 getBackgroundBuilder(AttributeSet attributeSet) {
        if (viewBgBuilder1 == null) {
            viewBgBuilder1 = new GYViewBgBuilder1(this, attributeSet);
        }
        return viewBgBuilder1;
    }

    @Override
    public GYViewSet getViewSet() {
        if (viewSet == null) {
            viewSet = new GYViewSet(this);
        }
        return viewSet;
    }

    public static class GYViewBgBuilder1 extends GYViewBgBuilder<GYTextView, GYViewBgBuilder1> {
        public GYViewBgBuilder1(View view) {
            super(view);
        }

        public GYViewBgBuilder1(View view, AttributeSet attributeSet) {
            super(view, attributeSet);
        }
    }

    private GYViewSet viewSet;

    public class GYViewSet extends GYViewSetSet<GYTextView, GYViewSet> {
        public GYViewSet(View view) {
            super(view);
        }

        public GYViewSet clearText() {
            setText("");
            return this;
        }

        public String getHintString() {
            if (TextUtils.isEmpty(getHint())) {
                return "";
            }
            return GYTextView.super.getHint().toString();
        }

        public String getTextString() {
            if (TextUtils.isEmpty(getText())) {
                return "";
            }
            return getText().toString();
        }

        public boolean isTextEmpty() {
            return TextUtils.isEmpty(getTextString());
        }

        public boolean isHintEmpty() {
            return TextUtils.isEmpty(getHintString());
        }

        public GYViewSet setDrawHorizontalLine(int drawHorizontalLine) {
            GYTextView.this.drawHorizontalLine = drawHorizontalLine;
            initDrawLine();
            return this;
        }

        public GYViewSet setTopDrawable(Drawable topDrawable) {
            GYTextView.this.topDrawable = topDrawable;
            initDrawable();
            return this;
        }

        public GYViewSet setBottomDrawable(Drawable bottomDrawable) {
            GYTextView.this.bottomDrawable = bottomDrawable;
            initDrawable();
            return this;
        }

        public GYViewSet setLeftDrawable(Drawable leftDrawable) {
            GYTextView.this.leftDrawable = leftDrawable;
            initDrawable();
            return this;
        }

        public GYViewSet setRightDrawable(Drawable rightDrawable) {
            GYTextView.this.rightDrawable = rightDrawable;
            initDrawable();
            return this;
        }

        public GYViewSet setDrawableSizePx(int drawableWidthPx, int drawableHeightPx) {
            GYTextView.this.drawableWidthPx = drawableWidthPx;
            GYTextView.this.drawableHeightPx = drawableHeightPx;
            setLeftDrawableSizePx(drawableWidthPx, drawableHeightPx);
            setTopDrawableSizePx(drawableWidthPx, drawableHeightPx);
            setRightDrawableSizePx(drawableWidthPx, drawableHeightPx);
            setBottomDrawableSizePx(drawableWidthPx, drawableHeightPx);
            return this;
        }

        public GYViewSet setDrawableSizeDp(int drawableWidthDp, int drawableHeightDp) {
            return setDrawableSizePx(GYDisplayUtils.dp2px(getContext(), drawableWidthDp), GYDisplayUtils.dp2px(getContext(), drawableHeightDp));
        }

        public GYViewSet setDrawableWidthPx(int drawableWidthPx) {
            return setDrawableSizePx(drawableWidthPx, drawableHeightPx);
        }

        public GYViewSet setDrawableWidthDp(int drawableWidthDp) {
            return setDrawableWidthPx(GYDisplayUtils.dp2px(getContext(), drawableWidthDp));
        }

        public GYViewSet setDrawableHeightPx(int drawableHeightPx) {
            return setDrawableSizePx(drawableWidthPx, drawableHeightPx);
        }

        public GYViewSet setDrawableHeightDp(int drawableHeightDp) {
            return setDrawableHeightPx(GYDisplayUtils.dp2px(getContext(), drawableHeightDp));
        }

        public GYViewSet setLeftDrawableSizePx(int leftDrawableWidthPx, int leftDrawableHeightPx) {
            GYTextView.this.leftDrawableWidthPx = leftDrawableWidthPx;
            GYTextView.this.leftDrawableHeightPx = leftDrawableHeightPx;
            initDrawable();
            return this;
        }

        public GYViewSet setLeftDrawableSizeDp(int leftDrawableWidthDp, int leftDrawableHeightDp) {
            return setLeftDrawableSizePx(GYDisplayUtils.dp2px(getContext(), leftDrawableWidthDp), GYDisplayUtils.dp2px(getContext(), leftDrawableHeightDp));
        }

        public GYViewSet setLeftDrawableWidthPx(int leftDrawableWidthPx) {
            return setLeftDrawableSizePx(leftDrawableWidthPx, leftDrawableHeightPx);
        }

        public GYViewSet setLeftDrawableHeightPx(int leftDrawableHeightPx) {
            return setLeftDrawableSizePx(leftDrawableWidthPx, leftDrawableHeightPx);
        }

        public GYViewSet setTopDrawableSizePx(int topDrawableWidthPx, int topDrawableHeightPx) {
            GYTextView.this.topDrawableWidthPx = topDrawableWidthPx;
            GYTextView.this.topDrawableHeightPx = topDrawableHeightPx;
            initDrawable();
            return this;
        }

        public GYViewSet setTopDrawableWidthPx(int topDrawableWidthPx) {
            return setTopDrawableSizePx(topDrawableWidthPx, topDrawableHeightPx);
        }

        public GYViewSet setTopDrawableHeightPx(int topDrawableHeightPx) {
            return setTopDrawableSizePx(topDrawableWidthPx, topDrawableHeightPx);
        }

        public GYViewSet setRightDrawableSizePx(int rightDrawableWidthPx, int rightDrawableHeightPx) {
            GYTextView.this.rightDrawableWidthPx = rightDrawableWidthPx;
            GYTextView.this.rightDrawableHeightPx = rightDrawableHeightPx;
            initDrawable();
            return this;
        }

        public GYViewSet setRightDrawableWidthPx(int rightDrawableWidthPx) {
            return setRightDrawableSizePx(rightDrawableWidthPx, rightDrawableHeightPx);
        }

        public GYViewSet setRightDrawableHeightPx(int rightDrawableHeightPx) {
            return setRightDrawableSizePx(rightDrawableWidthPx, rightDrawableHeightPx);
        }

        public GYViewSet setBottomDrawableSizePx(int bottomDrawableWidthPx, int bottomDrawableHeightPx) {
            GYTextView.this.bottomDrawableWidthPx = bottomDrawableWidthPx;
            GYTextView.this.bottomDrawableHeightPx = bottomDrawableHeightPx;
            initDrawable();
            return this;
        }

        public GYViewSet setBottomDrawableWidthPx(int bottomDrawableWidthPx) {
            return setBottomDrawableSizePx(bottomDrawableWidthPx, bottomDrawableHeightPx);
        }

        public GYViewSet setBottomDrawableHeightPx(int bottomDrawableHeightPx) {
            return setBottomDrawableSizePx(bottomDrawableWidthPx, bottomDrawableHeightPx);
        }

        /////////////////////////////////////////////////
        public GYViewSet setLeftDrawableWidthDp(int leftDrawableWidthDp) {
            return setLeftDrawableWidthPx(GYDisplayUtils.dp2px(getContext(), leftDrawableWidthDp));
        }

        public GYViewSet setLeftDrawableHeightDp(int leftDrawableHeightDp) {
            return setLeftDrawableHeightPx(GYDisplayUtils.dp2px(getContext(), leftDrawableHeightDp));
        }

        public GYViewSet setTopDrawableWidthDp(int topDrawableWidthDp) {
            return setTopDrawableWidthPx(GYDisplayUtils.dp2px(getContext(), topDrawableWidthDp));
        }

        public GYViewSet setTopDrawableHeightDp(int topDrawableHeightDp) {
            return setTopDrawableHeightPx(GYDisplayUtils.dp2px(getContext(), topDrawableHeightDp));
        }

        public GYViewSet setRightDrawableWidthDp(int rightDrawableWidthDp) {
            return setRightDrawableWidthPx(GYDisplayUtils.dp2px(getContext(), rightDrawableWidthDp));
        }

        public GYViewSet setRightDrawableHeightDp(int rightDrawableHeightDp) {
            return setRightDrawableHeightPx(GYDisplayUtils.dp2px(getContext(), rightDrawableHeightDp));
        }

        public GYViewSet setBottomDrawableWidthDp(int bottomDrawableWidthDp) {
            return setBottomDrawableWidthPx(GYDisplayUtils.dp2px(getContext(), bottomDrawableWidthDp));
        }

        public GYViewSet setBottomDrawableHeightDp(int bottomDrawableHeightDp) {
            return setBottomDrawableHeightPx(GYDisplayUtils.dp2px(getContext(), bottomDrawableHeightDp));
        }

        /////////////////////////////////////////////////
        public GYViewSet setMinWidthDp(int minPixelsDp) {
            return setMinWidthPx(GYDisplayUtils.dp2px(getContext(), minPixelsDp));
        }

        public GYViewSet setMinWidthPx(int minPixelsPx) {
            GYTextView.super.setMinWidth(minPixelsPx);
            return this;
        }

        public GYViewSet setMinHeightDp(int minPixelsDp) {
            return setMinHeightPx(GYDisplayUtils.dp2px(getContext(), minPixelsDp));
        }

        public GYViewSet setMinHeightPx(int minPixelsPx) {
            GYTextView.super.setMinHeight(minPixelsPx);
            return this;
        }

        public GYViewSet setMaxWidthDp(int maxPixelsDp) {
            return setMaxWidthPx(GYDisplayUtils.dp2px(getContext(), maxPixelsDp));
        }

        public GYViewSet setMaxWidthPx(int maxPixelsPx) {
            GYTextView.super.setMaxWidth(maxPixelsPx);
            return this;
        }

        public GYViewSet setMaxHeightDp(int maxPixelsDp) {
            return setMaxHeightPx(GYDisplayUtils.dp2px(getContext(), maxPixelsDp));
        }

        public GYViewSet setMaxHeightPx(int maxPixelsPx) {
            GYTextView.super.setMaxHeight(maxPixelsPx);
            return this;
        }

        public GYViewSet setTextSizeSp(float sizeSp) {
            GYTextView.super.setTextSize(sizeSp);
            return this;
        }

        public GYViewSet setTextSizePx(float sizePx) {
            return setTextSizeSp(GYDisplayUtils.px2sp(getContext(), sizePx));
        }

        public GYViewSet setTextSizeSp(int unit, float sizeSp) {
            GYTextView.super.setTextSize(unit, sizeSp);
            return this;
        }

        public GYViewSet setTextSizePx(int unit, float sizePx) {
            return setTextSizeSp(unit, GYDisplayUtils.px2sp(getContext(), sizePx));
        }

        public GYViewSet setHint(String hint) {
            if (TextUtils.isEmpty(hint)) {
                GYTextView.super.setHint("");
            } else {
                GYTextView.super.setHint(hint);
            }
            return this;
        }

        public GYViewSet setHintTextColor(int color) {
            GYTextView.super.setHintTextColor(color);
            return this;
        }

        public GYViewSet setHintTextColor(ColorStateList colors) {
            GYTextView.super.setHintTextColor(colors);
            return this;
        }

        public GYViewSet setEnabled(boolean enabled) {
            GYTextView.super.setEnabled(enabled);
            return this;
        }

        public GYViewSet setFocusable(boolean focusable) {
            GYTextView.super.setFocusable(focusable);
            return this;
        }

        public GYViewSet setFocusableInTouchMode(boolean focusableInTouchMode) {
            GYTextView.super.setFocusableInTouchMode(focusableInTouchMode);
            return this;
        }

        public GYViewSet requestFocus() {
            GYTextView.super.requestFocus();
            return this;
        }

        private GYViewSet setTextObject(Object object) {
            if (object == null) {
                setText("");
            } else {
                GYTextView.super.setText(String.valueOf(object));
            }
            return this;
        }

        public GYViewSet setText(String s) {
            return setTextObject(s);
        }

        public GYViewSet setText(Integer integer) {
            return setTextObject(integer);
        }

        public GYViewSet setText(Double d) {
            return setTextObject(d);
        }

        public GYViewSet setText(Float f) {
            return setTextObject(f);
        }

        public GYViewSet setText(Long l) {
            return setTextObject(l);
        }

        public GYViewSet addText(String text) {
            String s = getTextString();
            setText(s + text);
            return this;
        }

        public GYViewSet setTextColor(int color) {
            GYTextView.super.setTextColor(color);
            return this;
        }

        public GYViewSet setTextColor(ColorStateList colors) {
            GYTextView.super.setTextColor(colors);
            return this;
        }

        public GYViewSet setGravity(int gravity) {
            GYTextView.super.setGravity(gravity);
            return this;
        }

        public int getDrawHorizontalLine() {
            return drawHorizontalLine;
        }

        public boolean fitLength() {
            boolean fitLength = true;
            if (minLength != MATCH_PARENT && getLength() < minLength) {
                fitLength = false;
            }
            if (maxLength != MATCH_PARENT && getLength() > maxLength) {
                fitLength = false;
            }
            return fitLength;
        }

        public int getMinLength() {
            return minLength;
        }

        public GYViewSet setMinLength(int minLength) {
            GYTextView.this.minLength = minLength;
            String s = getTextString();
            setText("");
            setText(s);
            return this;
        }

        public boolean isBold() {
            return getTypeface().isBold();
        }

        protected boolean supportsAutoSizeText() {
            return true;
        }

        public GYViewSet setDrawableSpacingPx(int drawableSpacingPx) {
            GYTextView.super.setCompoundDrawablePadding(drawableSpacingPx);
            return this;
        }

        public GYViewSet setDrawableSpacingDp(int drawableSpacingDp) {
            return setDrawableSpacingPx(GYDisplayUtils.dp2px(getContext(), drawableSpacingDp));
        }

        public GYViewSet setDrawablePaddingPx(int drawablePaddingPx) {
            GYTextView.super.setCompoundDrawablePadding(drawablePaddingPx);
            return this;
        }

        public GYViewSet setDrawablePaddingDp(int drawablePaddingDp) {
            return setDrawablePaddingPx(GYDisplayUtils.dp2px(getContext(), drawablePaddingDp));
        }

        private int start;
        private int before;
        private String beforeString;

        private void initFilter() {
            addTextChangedListener(new TextWatcher() {
                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    beforeString = s.toString();
                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                    GYViewSet.this.start = start;
                    GYViewSet.this.before = before;
                }

                @Override
                public void afterTextChanged(Editable s) {
                    if (!TextUtils.isEmpty(digits)) {
                        for (int i = 0; i < s.length(); i++) {
                            if (!digits.contains(s.toString().substring(i, i + 1))) {
                                s.delete(i, i + 1);
                                return;
                            }
                        }
                    }
                    int beforeLength = GYTextUtils.getInstance().getLength(beforeString);
                    int nowLength = GYTextUtils.getInstance().getLength(s);
                    start = Math.max(start, before);
                    if (nowLength > beforeLength && maxLength >= 0 && nowLength > maxLength) {
                        int end = start + (s.length() - beforeString.length());
                        String addString = s.toString().substring(start, end);
                        for (int i = addString.length() - 1; i >= 0; i--) {
                            addString = addString.substring(0, i);
                            int nowStringLength = GYTextUtils.getInstance().getLength(beforeString + addString);
                            if (nowStringLength <= maxLength) {
                                s.replace(start, end, addString);
                                return;
                            }
                        }
                    }
                }
            });
        }

        public GYViewSet setMaxLength(int maxLength) {
            if (maxLength >= 0) {
                setFilters(new InputFilter[]{new InputFilter.LengthFilter(maxLength)});
            }
            GYTextView.this.maxLength = maxLength;
            if (maxLength < getLength() && maxLength >= 0) {
                setText(GYTextUtils.getInstance().getLengthString(getTextString(), maxLength));
            }
            return this;
        }

        public int getMaxLength() {
            return maxLength;
        }

        public int getLength() {
            return GYTextUtils.getInstance().getLength(getTextString());
        }

        private void initDrawable() {
            if (leftDrawable != null) {
                leftDrawable.setBounds(0, 0, leftDrawableWidthPx >= 0 ? leftDrawableWidthPx : leftDrawable.getIntrinsicWidth(), leftDrawableHeightPx >= 0 ? leftDrawableHeightPx : leftDrawable.getIntrinsicHeight());
            }
            if (topDrawable != null) {
                topDrawable.setBounds(0, 0, topDrawableWidthPx >= 0 ? topDrawableWidthPx : topDrawable.getIntrinsicWidth(), topDrawableHeightPx >= 0 ? topDrawableHeightPx : topDrawable.getIntrinsicHeight());
            }
            if (rightDrawable != null) {
                rightDrawable.setBounds(0, 0, rightDrawableWidthPx >= 0 ? rightDrawableWidthPx : rightDrawable.getIntrinsicWidth(), rightDrawableHeightPx >= 0 ? rightDrawableHeightPx : rightDrawable.getIntrinsicHeight());
            }
            if (bottomDrawable != null) {
                bottomDrawable.setBounds(0, 0, bottomDrawableWidthPx >= 0 ? bottomDrawableWidthPx : bottomDrawable.getIntrinsicWidth(), bottomDrawableHeightPx >= 0 ? bottomDrawableHeightPx : bottomDrawable.getIntrinsicHeight());
            }
            setCompoundDrawables(leftDrawable, topDrawable, rightDrawable, bottomDrawable);
        }

        private void initDrawLine() {
            int flags = 0;
            switch (drawHorizontalLine) {
                case HorizontalLine.HIDE:
                    flags = 0;
                    break;
                case HorizontalLine.CENTER:
                    flags = Paint.STRIKE_THRU_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG;
                    break;
                case HorizontalLine.BOTTOM:
                    flags = Paint.UNDERLINE_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG;
                    break;
                case HorizontalLine.ALL:
                    flags = Paint.STRIKE_THRU_TEXT_FLAG | Paint.UNDERLINE_TEXT_FLAG | Paint.ANTI_ALIAS_FLAG;
                    break;
            }
            getPaint().setFlags(flags);//设置中划线
        }

        public GYViewSet setBold(boolean bold) {
            setTypeface(bold ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
            return this;
        }

        public GYViewSet addDigits(String digits) {
            GYTextView.this.digits += digits;
            return this;
        }

        public GYViewSet setDigits(String digits) {
            GYTextView.this.digits = digits;
            return this;
        }

        public String getDigits() {
            return digits;
        }

        public GYViewSet setSingleLine(boolean singleLine) {
            int input = getInputType();
            int minHeight = getMinHeight();
            int maxHeight = getMaxHeight();
            GYTextView.super.setSingleLine(singleLine);
            setInputType(input);
            setMinHeightPx(minHeight);
            setMaxHeightPx(maxHeight);
            return this;
        }

        public GYViewSet setSingleLine() {
            return setSingleLine(true);
        }

        public GYViewSet setInputType(int type) {
            GYTextView.super.setInputType(type);
            return this;
        }
    }
}
